package com.wgo.precise.privilege;

import java.util.Set;

import com.wgo.bpot.domain.common.ServicePrivilege;
import com.wgo.bpot.domain.common.UserRole;
import com.wgo.bpot.domain.common.impl.UserRoleImpl;

public enum PreciseUserRole implements UserRole {
    ADMIN(PrecisePrivilege.values()),
    READER(PrecisePrivilege.READ),
    AUTHOR(PrecisePrivilege.CREATE_REQUIREMENT,PrecisePrivilege.READ);
    
    private UserRole userRole;

    private PreciseUserRole(ServicePrivilege...privileges){
        userRole = new UserRoleImpl(name());
        if (null != privileges) for (ServicePrivilege privilege : privileges) {
            userRole.addServicePrivilege(privilege);
        }
    }
    
    public void addNestedUserRole(UserRole userRole) {
        userRole.addNestedUserRole(userRole);
    }

    public String getName() {
        return userRole.getName();
    }

    public Set<UserRole> getNestedUserRoles() {
        return userRole.getNestedUserRoles();
    }

    public void removeNestedUserRole(UserRole userRole) {
        userRole.removeNestedUserRole(userRole);
    }

    public void setName(String name) {
        userRole.setName(name);
    }

    public void addServicePrivilege(ServicePrivilege servicePrivilege) {
        userRole.addServicePrivilege(servicePrivilege);
    }

//    public <T> boolean isAllowedIfApplicable(Service service, CrudOperation operation, Class<T> conceptType, T conceptInstance) {
//        return userRole.isAllowedIfApplicable(service, operation, conceptType, conceptInstance);
//    }

    public void removeServicePrivilege(ServicePrivilege servicePrivilege) {
        userRole.removeServicePrivilege(servicePrivilege);
    }
    
    public Set<ServicePrivilege> getServicePriviliges() {
        return userRole.getServicePriviliges();
    }

    public boolean isAllowed(ServicePrivilege... servicePrivileges) {
        return userRole.isAllowed(servicePrivileges);
    }

}
